<%@ page language="java" isELIgnored="false" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
	import="java.net.URLEncoder"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>根据航空公司生成CODE</title>

<link
	href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="<%=request.getContextPath() %>/fare/js/show.js"></script>
<link href="<%=request.getContextPath()%>/fare/css/base.css"
	rel="stylesheet" type="text/css" />
<script
	src="<%=request.getContextPath()%>/fare/js/datePicker/WdatePicker.js"
	type="text/javascript"></script>
 <script
	src="<%=request.getContextPath()%>/jsFile/js_new/jquery.1.7.2.js"
	type="text/javascript"></script> 
<script type="text/javascript"
	src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.all.js"></script>
<script
	src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/plugins/ligerGrid.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerDateEditor.js"
	type="text/javascript"></script>
<link rev="stylesheet" media="all"
	href="<%=request.getContextPath() %>/fare/css/form_style.css"
	type="text/css" rel="stylesheet" />
<%-- <script
	src="<%=request.getContextPath()%>/fare/js/ligerUI/js/ligerui.min.js"
	type="text/javascript"></script> --%>
<script
	src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerDialog.js"
	type="text/javascript"></script>
<%-- <script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/core/base.js" type="text/javascript"></script> --%>
<script src="<%=request.getContextPath()%>/fare/lib/json2.js"
	type="text/javascript"></script>
<link
	href="<%=request.getContextPath()%>/fare/js/ligerUI/skins/Aqua/css/ligerui-all.css"
	rel="stylesheet" type="text/css" />

<script type="text/javascript">

$(document).ready(function () {
	var $j = jQuery.noConflict();/* 这个很重要的，如果删除后面的ligerUI就用不了 */
	var griddata=${data};
	manager=jQuery("#maingrid").ligerGrid({
		    dataAction : 'server',
		    title:'URL详细信息',
			showTitle:true,
		    columns : columns,
		    data: { Rows: griddata },
		  //  url:url,
		    height: '80%',
	        width: '100%',
	        pageSizeOptions : [20,40,50,100],
			pageSize:20, 
			pagesizeParmName:'pagesize' ,
			 rownumbers:false,
            /* enabledEdit: true,
            checkbox : false,
            clickToEdit:false,  */
	        isScroll: true,
	        usePager:true,
	    //    AllowPaging:true,
           heightDiff: 100
			 
	 	});   
});


/* 清空 数据
 */
function clearcontent(){	
	jQuery("#select_dpmt").val("");
	
}
function checkForm(){
	if(jQuery('#select_dpmt').val()=='请选择' || jQuery('#select_dpmt').val()==" "){
		//alert('请选择航空公司!');
	        return false;
	}
	return true;
}

//刷新当前页面一次
function reurl(){
	 url = location.href; 
	 var times = url.split("?"); 
	 if(times[1] != 1){ 
	 url += "?1"; 
	 self.location.replace(url);
	 }
}
function copy(){
	var clip = null;
	var row = getSelect();
//	alert(row);
/* 	
//	alert("row=="+row.URLS);
	var texts=row.URLS;
	var getId=row.rowId;
	alert(getId); */
	var texts="hello";
	
	clip = new ZeroClipboard.Client();
	clip.setHandCursor(true );

	
	clip.addEventListener('complete', function (client, text) {
		debugstr("Copied text to clipboard: " + text );
	});
	clip.setText(texts);
	
	clip.glue("getRow_1");
	//alert("复制URL成功");
	/* clip.addEventListener( "complete", function(){
	    alert("复制URL成功！");
	}); */
}
function create(){
	
	if(checkForm()==true){
		var getRedio;
		var hbasekeySel=jQuery("#select_dpmt").val();
		var getDays=document.getElementById("days").value;
		var getHours=document.getElementById("hours").value;
		
		var k=document.getElementsByTagName("input");
		for(var l=0;l<k.length;l++){
	//	if(k[l].type=="radio"){
		if(k[l].checked){
			getRedio=k[l].value;
			break;
			}
		
		}
		
        jQuery.ligerDialog.confirm('确定要生成URL?',function(yes)
        {	if(yes){
        	 jQuery.post("<%=request.getContextPath()%>/registerCreateCodeAction!createRegisterCode.action?hbasekeySels="+hbasekeySel+"&days="+getDays+"&hours="+getHours+"&radioHours="+getRedio, 
        			[ {	name : 'jspData',value : JSON.stringify(hbasekeySel)}],
            			function(){
            		 		alert("生成URL成功");
            		 		<%-- window.location.href="<%=request.getContextPath() %>/registerCreateCodeAction!toRegisterCreateCodeJSP.action"; --%>
            		 		location.href = "<%=request.getContextPath() %>/pages/system/register/register_invitationcode.jsp";
            		 		reurl();
            	 		}
        			);
     //   	 manager.deleteRow(rowid);
        		}
        	});
	  	}
	 else{
		alert('请选择航空公司!');
	}  
	}
	
function find(){
	jQuery.noConflict();   
	var carrierKey=jQuery("#select_dpmt").val();	
	 jQuery("#dataForm").attr("action","<%=request.getContextPath()%>/registerCreateCodeAction!toRegisterCreateCodeJSP.action?carrierKey="+carrierKey);
	 jQuery("#dataForm").submit();
}
	
var nowDate  =  new Date().getTime();	
var  manager;	
var columns= [
			{ display: '序号', name: 'rowId', width: 40, 
				render: function(data, index) { 
					return (this.options.page-1)*this.options.pageSize+index+1;
					} 
			}, 
   			{ display: '航空公司',    name: 'name',width:100, isSort:false},
            { display: 'Hbase_KEY', name: 'hbaseKey',width:1 ,isSort:false,hide:true},
            { display: '公司英文缩写', name: 'carrierKey',width:80 ,isSort:false},
            { display: '邀请码',     name: 'registerCode',width:120, isSort:false},
            { display: 'URL',       name: 'URLS', align: "left", width:480 ,isSort:true,
            	render:function (record, rowindex, value, column){
            		if(varToDate(record.effectiveDate)>nowDate){
            			return "<a id='getRow_"+rowindex+"' style='position:relative'  onclick=''>"+record.URLS+"</a>";
            		}else{
            			return record.URLS
            		}
            	}
            },
            { display: '创建日期',  name: 'createTime', width:160 ,isSort:true},
            { display: '注册码有效日期',  name: 'effectiveDate', width:160, isSort:true,
            	render:function(record, rowindex, value, column){
            		if(varToDate(record.effectiveDate)>nowDate){
            			return "<a id='getRow_"+rowindex+"' style='position:relative'  onclick=''>"+record.effectiveDate+"</a>";
            		}else{
            			return record.effectiveDate
            		}
            	}
            }
            ];
 

function varToDate(str){
	var   strArray=str.split(" ");   
	var   strDate=strArray[0].split("-");   
	var   strTime=strArray[1].split(":");   
	var   a=new   Date(strDate[0],(strDate[1]-parseInt(1)),strDate[2],strTime[0],strTime[1],strTime[2]);
	return a.getTime();
}

//获取选中行信息
function getSelect() {
	var row = manager.getSelectedRow();
	if (!row) {
	//	$.ligerDialog.warn('请选您要操作的行！');
		return;
	} 
		return eval('(' + JSON.stringify(row) + ')');
	
}          
function timeFunction1(){
	jQuery("#days").val("");
	jQuery("#hours").val("");
	//$("[name='timeID']").attr("checked",true);//全选  
	jQuery("input[name=timeID][value=24]").attr("checked",true);
	jQuery("[name='timeID2']").removeAttr("checked");//取消全选
}

function timeFunction2(){
	jQuery("input[name=timeID2][value=0]").attr("checked",true);
	 jQuery("[name='timeID']").removeAttr("checked");//取消全选  
	
}

</script>

</head>
<body >
	<%-- <jsp:include page="../../inc/treelist2.jsp"></jsp:include> --%>

	<!--<div class="main main_max">
		 <div class="sideBar">
			<div class="box">
				<div class="location">当前位置： 个人中心 &gt; 注册URL生成</div>
			</div>
		</div>
 -->
		<div class="form_body">
			<div class="">
				<div class="form_table_tltle">URL生成设置</div>
				<%-- 生成form--%>
				<form id="dataForm" method="post" action="">
					<input type="hidden" name="result" id="result" value=" " />
					<table width="0" border="0" cellpadding="0" cellspacing="0"
						class="form_table">
						<tr>
							<td class="left">公司名:</td>
							<td><select name="registerVo.sourceId" id="select_dpmt">
									<option value=" ">请选择</option>
									<c:forEach var="bean" items="${sourceList}" varStatus="stat">
										<option value="${bean.hbaseKey}">${bean.name}</option>
									</c:forEach>
							</select></td>
							
							<td class="left" id="">注册码时效性：</td>
							<td>
							<input type="radio" name="timeID" id="oneDay" value="24" checked="checked" onclick="timeFunction1()"/>24小时
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="radio" name="timeID2" id="doMyself" value="0" onclick="timeFunction2()"/>自定义：
							<input type="text" value="" name="vo.days"  style="width:50px" id="days"   onmousedown="timeFunction2()"/>天
							<input type="text" value="" name="vo.hours" style="width:50px" id="hours"   onmousedown="timeFunction2()"/>小时
							
							</td>
							
							<TD><img
								src="<%=request.getContextPath() %>/fare/images/create_code.png"
								name="addbutton" id="addbutton"
								onclick="javascript:create()" /> <img
								src="<%=request.getContextPath() %>/fare/images/but_01.png"
								name="querybutton" id="querybutton"
								onclick="javascript:find();" /> <img
								src="<%=request.getContextPath() %>/fare/images/but_02.png"
								name="cancelbutton" id="cancelbutton"
								onclick="javascript:clearcontent();" /></TD>
						</tr>

					</table>
				</form>
				<!-- <div class="high_10"></div> -->

				<div id="maingrid" style="margin-top: 20px;"></div>
				<div id="norecord" style="margin-bottom: 1px; display: none">没有相关数据！</div>

			</div>
		</div>


	<!-- </div>
	<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br> -->
																<%-- 	<jsp:include page="../../inc/footer2.jsp"></jsp:include> --%>
</body>
</html>